package component.security.hardware;


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.security.PrivateKey;



import component.security.encrypt.Crypto;
import component.security.encrypt.Util;
import component.security.util.Constant;
import component.security.util.FileUtil;


/**
 * 获取硬件运行类
 *
 */
public class GetHardWareRunner {
	
	/**
	 * @preserve
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception{
		
		getHardWard();
		
		
		
	}
	
	/**
	 * 获取客户硬件
	 * @throws Exception
	 */
	private static void getHardWard()throws Exception{
	
		//获取加密硬件信息
		String filePath = FileUtil.getFileDir(Constant.NETWORK_FILE) ;
		String croptyFilePath = FileUtil.getFileDir(Constant.NETWORK_CRYPTO_FILE);
		byte[] obj = (byte[])FileUtil.readObjectFromFile(croptyFilePath);
		
		//用私钥解密
		String priKeyFile = FileUtil.getFileDir(Constant.PRIKEY_FILE);
		PrivateKey privateKey = Util.getPrivateKeyFromFile(priKeyFile);
		byte[] bytes  = (new Crypto()).decrypt(obj, privateKey);

		//加密文件写入文件
		FileUtil.writeString2File(filePath, new String(bytes));
		
		System.out.println("获取硬件成功！");
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		br.readLine();
	}
}
